package com.sharp.socket.io.config;

import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.listener.ExceptionListenerAdapter;
import com.sharp.kernel.utils.JsonUtil;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * Title: SockIoExceptionListener
 * Description: Copyright: Copyright (c) 2019 Company: BHFAE
 *
 * @author Sharp
 * @date 2020/10/13 14:01
 * @description Project Name: customer-robot
 * @Package: com.bhfae.customer.robot.chat.config.socket
 */
@Slf4j
public class SockIoExceptionListener extends ExceptionListenerAdapter {

    @Override
    public boolean exceptionCaught(ChannelHandlerContext ctx, Throwable e) {
        log.error("发生错误 :{}", e.getMessage());
        return true;
    }

    @Override
    public void onPingException(Exception e, SocketIOClient client) {
        log.error("客户端 {}====轮询异常 {}", client.getNamespace(), e.getMessage());
    }

    @Override
    public void onEventException(Exception e, List<Object> data, SocketIOClient client) {
        log.error("客户端 {}====event异常 {} , \n{}", client.getNamespace(), e.getMessage(), JsonUtil.toJson(data));
    }

    @Override
    public void onDisconnectException(Exception e, SocketIOClient client) {
        log.error("客户端 {}====断开异常 {}", client.getNamespace(), e.getMessage());
    }

    @Override
    public void onConnectException(Exception e, SocketIOClient client) {
        log.error("客户端 {}====连接异常 {}", client.getNamespace(), e.getMessage());
    }
}
